import 'package:flutter/material.dart';

import 'KeyBoardSubmit.dart';
import 'KeyboardButton.dart';

typedef KeyboardClickCallback = void Function(String name);

class CalcKeyboard extends StatefulWidget {

  final KeyboardClickCallback onchange;
  final VoidCallback onSubmit;

  const CalcKeyboard({Key key, this.onchange, this.onSubmit}) : super(key: key);

  @override
  _CalcKeyboardState createState() => _CalcKeyboardState();
}

class _CalcKeyboardState extends State<CalcKeyboard> {
  @override
  Widget build(BuildContext context) {
    return GridView(
      physics: NeverScrollableScrollPhysics(),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 4,
//        mainAxisSpacing: 10,
//        crossAxisSpacing: 16,
        childAspectRatio: 1
      ),
      children: getAllBtns(),
    );
  }

  List<Widget> getAllBtns() {
    List<Widget> btns = List();
    btns.add(KeyBoardButton(name: 'C', color: Color(0xffAAAAAA), onTap: widget.onchange,));
    btns.add(KeyBoardButton(name: '+/-', color: Color(0xffAAAAAA), onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '%', color: Color(0xffAAAAAA), onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '÷', color: Color(0xffFF3E39), onTap: widget.onchange));

    btns.add(KeyBoardButton(name: '7', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '8', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '9', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '*', color: Color(0xffFF3E39), onTap: widget.onchange));

    btns.add(KeyBoardButton(name: '4', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '5', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '6', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '+', color: Color(0xffFF3E39), onTap: widget.onchange));

    btns.add(KeyBoardButton(name: '1', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '2', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '3', color: Color(0xff1A1A1A), bold: true, onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '-', color: Color(0xffFF3E39), onTap: widget.onchange,));

    btns.add(KeyBoardButton(name: '.', color: Color(0xff1A1A1A), onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '0', color: Color(0xff1A1A1A), onTap: widget.onchange));
    btns.add(KeyBoardButton(name: '<-', onTap: widget.onchange ));
    btns.add(KeyBoardSubmit(name: '=', color: Color(0xffFF3E39), onSubmit: widget.onSubmit,));
    return btns;
  }

}